package org.jeecg.modules.jd.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.jd.entity.JD_goods;
import org.jeecg.modules.jd.entity.JD_order;
import org.jeecg.modules.pdd.util.DingDanXiaUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JDOrderUtil {



    public static List<JD_order> getOrders(JDOrderRequest jdOrderRequest) {

        String url = "http://api.tbk.dingdanxia.com/jd/order_details";
        Map<String, Object> map = new HashMap<>();
        map.put("apikey", DingDanXiaUtil.dingdanxia_appkey);
       // map.put("appkey", JDContants.appKey);
      //  map.put("secretkey", JDContants.appSecret);
        map.put("key", JDContants.key);
        if(null!= jdOrderRequest.getTime()) {
            map.put("time", jdOrderRequest.getTime());
        }
        if(null!= jdOrderRequest.getPageNo()) {
            map.put("pageNo", jdOrderRequest.getPageNo());
        }
        if(null!= jdOrderRequest.getPageSize()) {
            map.put("pageSize", jdOrderRequest.getPageSize());
        }
        if(null!= jdOrderRequest.getType()) {
            map.put("type", jdOrderRequest.getType());
        }
        String resultStr = "";
        try {
            resultStr = HttpUtil.post(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = JSON.parseObject(resultStr);
        String contentlist = jsonObject.getString("data");

        List<JD_order> jd_positionList = JSON.parseArray(contentlist, JD_order.class);
        return jd_positionList;

    }

    public static String  getOrdersDetail(String skuIds) {
        String url = "http://api.tbk.dingdanxia.com/jd/item_detail";
        Map<String, Object> map = new HashMap<>();
        map.put("apikey", DingDanXiaUtil.dingdanxia_appkey);
        map.put("skuIds", skuIds);
        String resultStr = "";
        try {
            resultStr = HttpUtil.post(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = JSON.parseObject(resultStr);
        String contentlist = jsonObject.getString("data");
        return contentlist;


    }


}
